{% extends "base.html" %}

{% block title %}Edit Trade{% endblock %}

{% block content %}
<!-- 导航栏 -->
<div class="side-navbar mb-3">
    <a class="navbar-brand" href="{{ url_for('index') }}">
        <i class="fas fa-chart-line"></i> Trading Analyzer
    </a>
    <a class="nav-link" href="{{ url_for('trades') }}">
        <i class="fas fa-list"></i> Trades
    </a>
    <a class="nav-link" href="{{ url_for('statistics_page') }}">
        <i class="fas fa-chart-bar"></i> Statistics
    </a>
</div>

<div class="row">
    <div class="col-md-8 offset-md-2">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">Edit Trade</h3>
            </div>
            <div class="card-body">
                <form method="post">
                    <div class="row">
                        <div class="col-md-6">
                            <h4>Basic Information</h4>
                            <div class="form-group">
                                <label for="symbol">Symbol</label>
                                <input type="text" class="form-control" id="symbol" name="symbol" 
                                       value="{{ trade.symbol }}" required>
                            </div>
                            <div class="form-group">
                                <label for="open_date">Open Date</label>
                                <input type="date" class="form-control" id="open_date" name="open_date" 
                                       value="{{ trade.open_date }}" required>
                            </div>
                            <div class="form-group">
                                <label for="open_time">Open Time</label>
                                <input type="time" class="form-control" id="open_time" name="open_time" 
                                       value="{{ trade.open_time }}" required>
                            </div>
                            <div class="form-group">
                                <label for="open_price">Open Price</label>
                                <input type="number" step="0.01" class="form-control" id="open_price" 
                                       name="open_price" value="{{ trade.open_price }}" required>
                            </div>
                            <div class="form-group">
                                <label for="open_qty">Open Quantity</label>
                                <input type="number" class="form-control" id="open_qty" name="open_qty" 
                                       value="{{ trade.open_qty }}" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <h4>Close Information</h4>
                            <div class="form-group">
                                <label for="close_date">Close Date</label>
                                <input type="date" class="form-control" id="close_date" name="close_date" 
                                       value="{{ trade.close_date }}" required>
                            </div>
                            <div class="form-group">
                                <label for="close_time">Close Time</label>
                                <input type="time" class="form-control" id="close_time" name="close_time" 
                                       value="{{ trade.close_time }}" required>
                            </div>
                            <div class="form-group">
                                <label for="close_price">Close Price</label>
                                <input type="number" step="0.01" class="form-control" id="close_price" 
                                       name="close_price" value="{{ trade.close_price }}" required>
                            </div>
                            <div class="form-group">
                                <label for="close_qty">Close Quantity</label>
                                <input type="number" class="form-control" id="close_qty" name="close_qty" 
                                       value="{{ trade.close_qty }}" required>
                            </div>
                        </div>
                    </div>

                    <div class="row mt-4">
                        <div class="col-md-6">
                            <h4>Trade Details</h4>
                            <div class="form-group">
                                <label for="direction">Direction</label>
                                <select class="form-control" id="direction" name="direction" required>
                                    <option value="Long" {% if trade.direction == 'Long' %}selected{% endif %}>Long</option>
                                    <option value="Short" {% if trade.direction == 'Short' %}selected{% endif %}>Short</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="trade_type">Trade Type</label>
                                <input type="text" class="form-control" id="trade_type" name="trade_type" 
                                       value="{{ trade.trade_type }}" required>
                            </div>
                            <div class="form-group">
                                <label for="open_session">Open Session</label>
                                <select class="form-control" id="open_session" name="open_session" required>
                                    <option value="RTH" {% if trade.open_session == 'RTH' %}selected{% endif %}>RTH</option>
                                    <option value="ETH" {% if trade.open_session == 'ETH' %}selected{% endif %}>ETH</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="close_session">Close Session</label>
                                <select class="form-control" id="close_session" name="close_session" required>
                                    <option value="RTH" {% if trade.close_session == 'RTH' %}selected{% endif %}>RTH</option>
                                    <option value="ETH" {% if trade.close_session == 'ETH' %}selected{% endif %}>ETH</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <h4>Profit & Loss</h4>
                            <div class="form-group">
                                <label for="gross_profit">Gross Profit</label>
                                <input type="number" step="0.01" class="form-control" id="gross_profit" 
                                       name="gross_profit" value="{{ trade.gross_profit }}" required>
                            </div>
                            <div class="form-group">
                                <label for="net_profit">Net Profit</label>
                                <input type="number" step="0.01" class="form-control" id="net_profit" 
                                       name="net_profit" value="{{ trade.net_profit }}" required>
                            </div>
                            <div class="form-group">
                                <label for="commission">Commission</label>
                                <input type="number" step="0.01" class="form-control" id="commission" 
                                       name="commission" value="{{ trade.commission }}" required>
                            </div>
                            <div class="form-group">
                                <label for="holding_time">Holding Time</label>
                                <input type="text" class="form-control" id="holding_time" name="holding_time" 
                                       value="{{ trade.holding_time }}" required>
                            </div>
                        </div>
                    </div>

                    <div class="form-group mt-4">
                        <button type="submit" class="btn btn-primary">Save Changes</button>
                        <a href="{{ url_for('trades') }}" class="btn btn-secondary">Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %} 